package com.jjb.www.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.jjb.www.R;
import com.jjb.www.app.AppAdapter;
import com.jjb.www.http.api.InvoiceListApi;

/**
 *    author : Android CRG
 *    github : https://github.com/getActivity/AndroidProject
 *    time   : 2018/11/05
 *    desc   : 可进行拷贝的副本
 */
public final class InvoiceListAdapter extends AppAdapter<InvoiceListApi.Bean> {
    public InvoiceListAdapter(Context context) {
        super(context);
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {
        private ShapeImageView mImgCk;
        private ShapeImageView mImgType;
        private ShapeTextView mTvTltle;
        private ShapeTextView mTvPrice;
        private ShapeTextView mTvTime;
        private ShapeTextView mTvPayType;



        private ViewHolder() {
            super(R.layout.item_invoice_list);
            mImgCk = findViewById(R.id.img_ck);
            mImgType = findViewById(R.id.img_type);
            mTvTltle = findViewById(R.id.tv_tltle);
            mTvPrice = findViewById(R.id.tv_price);
            mTvTime = findViewById(R.id.tv_time);
            mTvPayType = findViewById(R.id.tv_pay_type);
        }

        @Override
        public void onBindView(int position) {
            InvoiceListApi.Bean bean = getItem(position);
            if (bean.getSelect()) {
                setTag(position);
                mImgCk.setImageResource(R.mipmap.icon_inve_ck_yes);
            } else {
                if (bean.getInvoice_status()==1||bean.getInvoice_status()==2||bean.getInvoice_status()==4){
                    mImgCk.setImageResource(R.mipmap.icon_inve_ck_or);
                }else {
                    mImgCk.setImageResource(R.mipmap.icon_inve_ck_no);
                }
            }

            if (bean.getImg_type()==1){
                mImgType.setImageResource(R.mipmap.icon_pay_blue);
            }else if (bean.getImg_type()==2){
                mImgType.setImageResource(R.mipmap.icon_pay_org);
            }else if (bean.getImg_type()==3){
                mImgType.setImageResource(R.mipmap.icon_pay_red);
            }else {
                mImgType.setImageResource(R.mipmap.icon_pay_black);
            }
            mTvTltle.setText(bean.getOrder_type_name());
            mTvPrice.setText(bean.getPay_money());
            mTvPayType.setText(bean.getPay_method_id());
            //0可开票 1开票中 2已开票 3开票失败  4开票过期
            if (bean.getInvoice_status()==0){
                mTvTime.setText(bean.getCreate_time());
            }else if (bean.getInvoice_status()==1){
                mTvTime.setText(bean.getCreate_time());
            }else if (bean.getInvoice_status()==2){
                mTvTime.setText(bean.getCreate_time());
            }else if (bean.getInvoice_status()==3){
                mTvTime.setText(bean.getCreate_time());
            }else if (bean.getInvoice_status()==4){
                mTvTime.setText("已过期");
                mImgCk.setImageResource(R.mipmap.icon_inve_ck_or);
                mTvTltle.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_BFBFBF))
                        .intoTextColor();
                mTvPrice.getTextColorBuilder()
                        .setTextColor(ContextCompat.getColor(getContext(), R.color.color_BFBFBF))
                        .intoTextColor();
            }


        }
    }
}